<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改权限</title>
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/commom.css">
</head>
<body>
<div>
    <span class="layui-breadcrumb">
        <a href="/" target="_top">首页</a>
        <a href="/resource">权限管理</a>
        <a><cite>修改</cite></a>
    </span>
</div>
<div class="form-style">
    <form class="layui-form" action="/resource/update" method="post"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
        <div class="layui-form-item">
            <label class="layui-form-label">权限名称</label>
            <div class="layui-input-block">
                <input type="hidden" name="permisId" value="${resource.permisId}">
                <input type="text" name="permisName" value="${resource.permisName}"  lay-verify="required" placeholder="请输入权限名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" id="typeDiv">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-block">
                <select name="permisType" id="type"  lay-filter="type" lay-verify="required">
                    <option value="-1">--请选择权限类型--</option>
                    <option <c:if test="${resource.permisType ==1}"> selected </c:if> value="1">模块</option>
                    <option <c:if test="${resource.permisType ==2}"> selected </c:if> value="2">功能</option>
                    <option <c:if test="${resource.permisType ==3}"> selected </c:if> value="3">按钮</option>
                    <option <c:if test="${resource.permisType ==4}"> selected </c:if> value="4">附属操作</option>
                    <option <c:if test="${resource.permisType ==9}"> selected </c:if> value="9">默认权限</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item" id="uriDiv" <c:if test="${resource.permisType ==1}"> style="display: none" </c:if> >
            <label class="layui-form-label">URI</label>
            <div class="layui-input-block">
                <input type="text" name="relateUrl" value="${resource.relateUrl}" placeholder="请输入uri" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" id="parentIdDiv" <c:if test="${resource.permisType ==1||resource.permisType ==9}"> style="display: none" </c:if>>
            <label class="layui-form-label">父级权限</label>
            <div class="layui-input-block">
                <select name="parentId" id="parentItem">
                    <c:forEach items="${parentList}" var="parent">
                        <option value="${parent.permisId}" <c:if test="${parent.permisId ==resource.parentId}"> selected </c:if> >${parent.permisName}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
      <%--  <div class="layui-form-item" id="btnIdDiv" <c:if test="${resource.permisType !=3}"> style="display: none" </c:if>>
            <label class="layui-form-label">按钮id</label>
            <div class="layui-input-block">
                <input type="text" name="btnId" value="${resource.btnId}" lay-verify="required" placeholder="请输入按钮id" autocomplete="off" class="layui-input">
            </div>
        </div>--%>
        <div class="layui-form-item" >
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="formDemo">完成</button>
                <a href="/resource"><button type="button" class="layui-btn layui-btn-primary">取消</button></a>
            </div>
        </div>
    </form>
</div>
<script src="/static/plugins/jquery.js"></script>
<script src="/static/plugins/layui/layui.js"></script>
<script>
    layui.use(['form','element'], function(){
        var form = layui.form;
        form.on('select(type)', function(data){
            var val = data.value;
            if (val>1){
                $('#parentIdDiv').show();
                $('#parentIdDiv').find('select').attr('lay-verify','required');
                if (val ==9) {
                    $('#parentIdDiv').hide();
                    $('#parentIdDiv').find('select').removeAttr('lay-verify');
                }
                if(val ==3){
                    $('#btnIdDiv').show();
                    $('#btnIdDiv').find('input').attr('lay-verify','required');
                }else {
                    $('#btnIdDiv').hide();
                    $('#btnIdDiv').find('input').removeAttr('lay-verify');
                }
                $('#uriDiv').show();
                $('#uriDiv').find('input').attr('lay-verify','required');

            }else {
                $('#uriDiv').hide();
                $('#uriDiv').find('input').removeAttr('lay-verify');
                $('#btnIdDiv').hide();
                $('#btnIdDiv').find('input').removeAttr('lay-verify');
                $('#parentIdDiv').hide();
                $('#parentIdDiv').find('select').removeAttr('lay-verify');
            }

            if (val>1&&val<5){
                $("#parentItem").empty();
                $.ajax({
                    url:"/resource/type/list",
                    type:"get",
                    data:{type:val==2?1:2},
                    dataType:"json",
                    success:function (data) {
                        $.each(data.data,function (i,item) {
                            $("#parentItem").append("<option value='"+item.permisId+"'>"+item.permisName+"</option>");
                        })
                        form.render('select'); //刷新select选择框渲染
                    },
                    error:function () {
                        console.log(data.message);
                    }
                })
            }
        });
    });
</script>
</body>
</html>
